package com.map.lbs;

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Matrix;

public class ImageHelper {
	
	public static byte[] getImageBytes(Bitmap image, int width, int height){
		//Scale image
		int originalWidth = image.getWidth();
		int originalHeight = image.getHeight();
		
		float scaleWidth = ((float)width)/originalWidth;
		float  scaleHeight = ((float)height)/originalHeight;
		Matrix  matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		
		Bitmap scaleImage = Bitmap.createBitmap(image, 0, 0, originalWidth, originalHeight, matrix, true);
		
		//convert image to bytes
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		scaleImage.compress(CompressFormat.JPEG, 100, bytes);
		
		return bytes.toByteArray();
	}
}
